package a09_贪心算法;

/**
 * <p>
 * a13_柠檬水找零复习1
 * </p>
 *
 * @author flyduck
 * @since 2025/1/15
 */
public class a13_柠檬水找零复习1 {
    public static void main(String[] args) {
        lemonadeChange(new int[]{5,5,5,10,20});
    }
    public static boolean lemonadeChange(int[] bills) {
        int five = 0;
        int ten = 0;
        int twenty = 0;
        for (int i = 0; i < bills.length; i++) {
            if(bills[i] == 5){
                five++;
            }else if(bills[i] == 10){
                if(five < 1){
                    return false;
                }
                five--;
                ten++;
            }else {//20
                if (ten > 0 && five > 0) {
                    ten--;
                    five--;
                    twenty++;
                }else if(five >= 3){
                    five -= 3;
                    twenty++;
                }else {
                    return false;
                }
            }
        }
        return true;
    }
}
